package com.rankeiot.platform.inner;

import com.rankeiot.core.util.JSONUtil;
import lombok.Data;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@Data
public class PluginInfo {
    String path;
    Map properties;

    public void write() throws IOException {
        JSONUtil.getObjectMapper().writeValue(new File(path, "plugin.json"), properties);
    }

    public void read() throws IOException {
        File pluginFile = new File(path, "plugin.json");
        if(!pluginFile.exists()){
            properties=new HashMap();
        }else{
            properties = JSONUtil.getObjectMapper().readValue(pluginFile, Map.class);
        }
    }
    public <T> T get(String name){
        return (T)properties.get(name);
    }
}
